import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:pointer_interceptor/pointer_interceptor.dart';

import '../message/models/bt_chat_model.dart';
import '../message/repository/bt_message_repository.dart';

showChatActionsModal(BuildContext context, String userId, BtChatModel model) {
  BtMessageRepository repository = BtMessageRepository();
  showModalBottomSheet(
      context: context,
      isScrollControlled: true,
      builder: (_) => PointerInterceptor(
            child: Container(
              height: 242,
              decoration: BoxDecoration(
                color: const Color(0xFFFFFFFF),
                borderRadius: BorderRadius.circular(6),
              ),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  InkWell(
                    child: Container(
                      height: 56,
                      decoration: const BoxDecoration(
                        border: Border(
                          bottom: BorderSide(
                            color: Color(0xFFEEEEEE),
                          ),
                        ),
                      ),
                      child: Center(
                        child: Text(
                          model.followed ? "Followed" : "Follow",
                          textAlign: TextAlign.center,
                          style: const TextStyle(color: Color(0xFF404040), fontSize: 17),
                        ),
                      ),
                    ),
                    onTap: () {
                      if (model.followed) {
                        return;
                      }

                      EasyLoading.show(status: 'Loading...');
                      repository.addFriend(userId, (success, msg) {
                        if (success) {
                          model.setFollowed(true);
                          Navigator.of(context).pop();
                        }
                        EasyLoading.showToast(msg);
                      });
                    },
                  ),
                  InkWell(
                    child: Container(
                      height: 56,
                      decoration: const BoxDecoration(
                        border: Border(
                          bottom: BorderSide(
                            color: Color(0xFFEEEEEE),
                          ),
                        ),
                      ),
                      child: const Center(
                        child: Text(
                          "Block",
                          textAlign: TextAlign.center,
                          style: TextStyle(color: Color(0xFF404040), fontSize: 17),
                        ),
                      ),
                    ),
                    onTap: () {
                      EasyLoading.show(status: 'Loading...');
                      repository.reportOrBlock(userId, 'Block', '', (success, msg) {
                        if (success) {
                          context.router.back();
                          Navigator.of(context).pop();
                        }
                        EasyLoading.showToast(msg);
                      });
                    },
                  ),
                  InkWell(
                    child: const SizedBox(
                      height: 56,
                      child: Center(
                        child: Text(
                          "Report",
                          textAlign: TextAlign.center,
                          style: TextStyle(color: Color(0xFF404040), fontSize: 17),
                        ),
                      ),
                    ),
                    onTap: () {
                      Navigator.of(context).pop();
                      showReportActionsModal(context, userId);
                    },
                  ),
                  const Divider(
                    thickness: 8,
                    color: Color(0xFFF6F7F8),
                  ),
                  InkWell(
                    child: const SizedBox(
                      height: 56,
                      child: Center(
                        child: Text(
                          "Cancel",
                          textAlign: TextAlign.center,
                          style: TextStyle(color: Color(0xFF404040), fontSize: 17),
                        ),
                      ),
                    ),
                    onTap: () {
                      Navigator.of(context).pop();
                    },
                  ),
                ],
              ),
            ),
          ));
}

showReportActionsModal(BuildContext context, String userId) {
  BtMessageRepository repository = BtMessageRepository();
  showModalBottomSheet(
      context: context,
      isScrollControlled: true,
      builder: (_) => PointerInterceptor(
            child: Container(
              height: 360,
              decoration: BoxDecoration(
                color: const Color(0xFFFFFFFF),
                borderRadius: BorderRadius.circular(6),
              ),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  InkWell(
                    child: Container(
                      height: 56,
                      decoration: const BoxDecoration(
                        border: Border(
                          bottom: BorderSide(
                            color: Color(0xFFEEEEEE),
                          ),
                        ),
                      ),
                      child: const Center(
                        child: Text(
                          "Pornographic",
                          textAlign: TextAlign.center,
                          style: TextStyle(color: Color(0xFF404040), fontSize: 17),
                        ),
                      ),
                    ),
                    onTap: () {
                      EasyLoading.show(status: 'Loading...');
                      repository.reportOrBlock(userId, 'Report', 'Pornographic', (success, msg) {
                        if (success) {
                          Navigator.of(context).pop();
                        }
                        EasyLoading.showToast(msg);
                      });
                    },
                  ),
                  InkWell(
                    child: Container(
                      height: 56,
                      decoration: const BoxDecoration(
                        border: Border(
                          bottom: BorderSide(
                            color: Color(0xFFEEEEEE),
                          ),
                        ),
                      ),
                      child: const Center(
                        child: Text(
                          "False gender",
                          textAlign: TextAlign.center,
                          style: TextStyle(color: Color(0xFF404040), fontSize: 17),
                        ),
                      ),
                    ),
                    onTap: () {
                      EasyLoading.show(status: 'Loading...');
                      repository.reportOrBlock(userId, 'Report', 'False gender', (success, msg) {
                        if (success) {
                          Navigator.of(context).pop();
                        }
                        EasyLoading.showToast(msg);
                      });
                    },
                  ),
                  InkWell(
                    child: const SizedBox(
                      height: 56,
                      child: Center(
                        child: Text(
                          "Fraud",
                          textAlign: TextAlign.center,
                          style: TextStyle(color: Color(0xFF404040), fontSize: 17),
                        ),
                      ),
                    ),
                    onTap: () {
                      EasyLoading.show(status: 'Loading...');
                      repository.reportOrBlock(userId, 'Report', 'Fraud', (success, msg) {
                        if (success) {
                          Navigator.of(context).pop();
                        }
                        EasyLoading.showToast(msg);
                      });
                    },
                  ),
                  InkWell(
                    child: const SizedBox(
                      height: 56,
                      child: Center(
                        child: Text(
                          "Political sensitive",
                          textAlign: TextAlign.center,
                          style: TextStyle(color: Color(0xFF404040), fontSize: 17),
                        ),
                      ),
                    ),
                    onTap: () {
                      EasyLoading.show(status: 'Loading...');
                      repository.reportOrBlock(userId, 'Report', 'Political sensitive', (success, msg) {
                        if (success) {
                          Navigator.of(context).pop();
                        }
                        EasyLoading.showToast(msg);
                      });
                    },
                  ),
                  InkWell(
                    child: const SizedBox(
                      height: 56,
                      child: Center(
                        child: Text(
                          "Other",
                          textAlign: TextAlign.center,
                          style: TextStyle(color: Color(0xFF404040), fontSize: 17),
                        ),
                      ),
                    ),
                    onTap: () {
                      EasyLoading.show(status: 'Loading...');
                      repository.reportOrBlock(userId, 'Report', 'Other', (success, msg) {
                        if (success) {
                          Navigator.of(context).pop();
                        }
                        EasyLoading.showToast(msg);
                      });
                    },
                  ),
                  const Divider(
                    thickness: 8,
                    color: Color(0xFFF6F7F8),
                  ),
                  InkWell(
                    child: const SizedBox(
                      height: 56,
                      child: Center(
                        child: Text(
                          "Cancel",
                          textAlign: TextAlign.center,
                          style: TextStyle(color: Color(0xFF404040), fontSize: 17),
                        ),
                      ),
                    ),
                    onTap: () {
                      Navigator.of(context).pop();
                    },
                  ),
                ],
              ),
            ),
          ));
}
